<template>
  <a-tabs defaultActiveKey="1" :style="{ marginTop: '12px',height:'440px',background:'#fff' }" @change="ruleTabChange">
    <a slot="tabBarExtraContent" @click="loadMore(key)" style="margin-right:10px">更多</a>
    <a-tab-pane key="1">
      <span slot="tab"><a-icon type="tags" style="margin-right:5px" theme="filled"/>规章制度</span>
      <!--展示规章制度信息-->
      <template v-if="formData.ruleInfo.length>0">
        <a-list itemLayout="horizontal" :dataSource="formData.ruleInfo">
          <a-list-item @click="showDetail(item)" slot="renderItem" :key="index" slot-scope="item, index" style="margin:0 10px">
            <div @click.stop="eyeClick(item)"><a-icon type="eye"  style="margin-right: 5px" />{{item.readTimes==0?'':item.readTimes}}</div>
            <a href="#" style="margin-left: 5px;color:#000000">
              <j-ellipsis :value="item.title" :length="15"/>
            </a>
            <div class="ant-list-item-content">{{item.createTime}}</div>
          </a-list-item>
        </a-list>
      </template>
      <template v-else>
        <a-empty />
      </template>
    </a-tab-pane>
    <a-tab-pane key="2">
      <span slot="tab"><a-icon type="download" style="margin-right:5px"></a-icon> 常用下载</span>
      <a-list itemLayout="horizontal" :dataSource="formData.downloadInfo" >
        <a-list-item slot="renderItem" :key="index" slot-scope="item, index" style="margin:0 20px" @click="recordDownload(item)">
          <div @click.stop="eyeClick(item)"><a-icon type="eye"  style="margin-right: 5px" />{{item.readTimes==0?'':item.readTimes}}</div>
          <a style="margin-left: 5px;color:#000000" :href="getFileDownloadUrl(item.fileUrl)" target="_blank">
            <j-ellipsis :value="item.title" :length="15"/>
          </a>
          <div class="ant-list-item-content">{{item.createTime}}</div>
        </a-list-item>
      </a-list>
    </a-tab-pane>
  </a-tabs>
</template>

<script>
  import { getFileAccessHttpUrl } from '@/api/manage'
  import store from '@/store/'
  import JEllipsis from '@/components/jeecg/JEllipsis'

  export default {
    name: 'EoaCmsRuleInfo',
    components: {
      JEllipsis,
    },
    props: ['formData'],
    data () {
      return {
        key: 'A02',
      }
    },
    methods: {
      ruleTabChange(key){
        if(key=='1'){
          this.key='A02';
        }else{
          this.key='A04';
        }
      },
      loadMore(type){
        this.$router.push({ path: '/modules/eoa/cms/eoaCmsArticlePortal',query:{type:type}})
      },
      showDetail(item){
        this.$router.push({ path: '/modules/eoa/cms/modules/eoaCmsArticleDetailModal',query : { item:item }})
      },
      getFileDownloadUrl: function (path) {
        return getFileAccessHttpUrl(path)
      },
      eyeClick(item){
        this.$refs.readerModal.loadReader(item);
      },
      recordDownload(item){
        if(item.id && store.getters.userInfo.username){
          getAction("/eoa/cms/eoaCmsArticleRead/recordReader",{articleId:item.id,username:store.getters.userInfo.username}).then((res) =>{
            if(res.success){
              console.log(res);
            }
          });
        }else{
          if(!this.item.id){
            this.$message.warning("文章信息异常");
          }else{
            this.$message.warning("登录信息异常");
          }
        }
      },
    }
  }
</script>

<style scoped>

</style>